﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DirectSalesList.aspx.cs" Inherits="IHISCETeim.Web.MachineSys.FXModel.DirectSalesList" %>
<%--直销列表--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../EasyUI/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="../EasyUI/themes/icon.css" />

	<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>   
	<script type="text/javascript" src="../EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../EasyUI/easyui-lang-zh_CN.js"></script>
    <link href="../themes/css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery.autocomplete.js" type="text/javascript"></script>
    <script>
        $(document).ready(function () {
            //自动完成
            $(".autocomplete").each(function () {
                var $this = $(this);
                var url = unescape($this.attr("autocompletehref"));
                $this.autocomplete(url);
            });
           
        })
    </script>
</head>
<body style="margin:2px;" >
   
   

    <div id="tab_list"></div>
    <div id="tab_toolbar" style="padding:2px;">
       <a href="#" onclick="$('#form_edit input').val('');OpenWin();return false;" id="a_add" class="easyui-linkbutton" iconcls="icon-add" plain="true">添加</a>
       <a title="修改"  rel="FXFinanceLeaseUpdate" onclick="EditSingData(this);return false;" class="easyui-linkbutton" iconcls="icon-save" plain="true">修改</a>
       <a title="删除"  class="easyui-linkbutton" onclick="DelData(this);return false;" iconcls="icon-remove" plain="true">删除</a>       
       <a title="查找"  class="easyui-linkbutton" onclick="InitSearch(this);return false;" iconcls="icon-search" plain="true">查找</a>

        <a title="高级查找"  class="easyui-linkbutton" onclick="AdjSearch(this);return false;" iconcls="icon-search" plain="true">高级查找</a>
    </div>   
    <div id="tab_search" title="查询条件" style=" height:250px; width:300px;" class="easyui-dialog" modal="true" closed="true" buttons="#search-buttons">
        <table class="table_search" width="100%" style=" line-height:21px;">
            <tr>
                <td>合同号:</td>
                <td><input id="tab_list_ContractNum" name="ContractNum" value="" /></td>
            </tr>
            <tr>
                <td>经销商:</td>
                <td><input name="AliasName" type="text" class="autocomplete" size="8" value="" autocompletehref="<%=AutoCompleteRequestUrl %>?ajaxmethod=getagentlist" mustMatch="true" swidth="300" showinputid=""/></td>
            </tr>
        </table>
        <div id="search-buttons">
            <a id="btn_search" href="javascript:;" class="easyui-linkbutton" iconcls="icon-search" plain="true">提交</a> 
            <a href="javascript:;" class="easyui-linkbutton" onclick="$('#tab_search').dialog('close');return false;" iconcls="icon-cancel" plain="true">取消</a>
        </div>
    </div>
    
   
     
    <script>
        $(document).ready(function () {
            //加载数据
            InitGird();           
        })
        //加载列表数据
        function InitGird() {
            $('#tab_list').datagrid({               
                url: location.href, //请求数据的页面
                sortName: 'LeaseStatus', //排序字段
                sortOrder: 'desc', //排序类型
                idField: 'FnncLsId', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度    
                height: $(parent.document).find(".tabsPageContent").height() - 11 > 0 ? $(parent.document).find(".tabsPageContent").height() - 11 : 500,
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                singleSelect: true, //是否只能选中一条
                remoteSort: true, //定义是否从服务器给数据排序
                frozenColumns: [[//冻结的列，不会随横向滚动轴移动
//	                {field: 'cbx', checkbox: true },
                //	{ title: 'FnncLsId2', field: 'FnncLsId', width: 150, sortable: true },
                    {title: 'AliasName', field: 'AliasName', width: 150 }
				]],
                columns: [[
                    { title: 'CustomerName', field: 'CustomerName', width: 120, sortable: true },
                    { title: 'MachineType', field: 'MachineType', width: 100, sortable: true },
                    { title: 'SerialNumber', field: 'SerialNumber', width: 150,editor:"text" },
                    { title: 'CustomerMobile', field: 'CustomerMobile', width: 150 },
                    { title: 'GPSStatus', field: 'GPSStatus', formatter: function (value, rec, index) { if (value == undefined) return; return value == 0 ? '服务中' : '停止服务' }, width: 100,
                        editor: {
                            type: "combobox",
                            options: {
                                valueField: 'GPSStatus',
                                textField: 'GPSStatusText',
                                data: [{ GPSStatus: '0', GPSStatusText: "服务中" }, { GPSStatus: '1', GPSStatusText: "停止服务"}],
                                required: true
                            }
                        }
                    },
                    { title: 'OGetDate', field: 'OGetDate', formatter: formatterdate, width: 150 },

                    { title: 'LPay', field: 'LPay', formatter: milliformatter, width: 150 },
                    { title: '操作', field: 'FnncLsId', width: 80, formatter: function (value, row, index) {
                        //alert(value); // $('#tab_list').datagrid("pageSize")
                        if (value == undefined) return;
                        //return '<a style="color:red" title="修改" href="FXFinanceLeaseUpdate.aspx?FnncLsId=' + value + '" rel="FXFinanceLeaseUpdate" onclick="EditData(this,' + value + ');$(this).parent().click();return false;">修改</a>';
                        if (row.editing) {
                            var s = '<a href="#" onclick="saverow(' + index + ')">Save</a> ';
                            var c = '<a href="#" onclick="cancelrow(' + index + ')">Cancel</a>';
                            return s + c;
                        } else {
                            var e = '<a href="#" onclick="editrow(' + index + ')">Edit</a> ';
                            var d = '<a href="#" onclick="deleterow(' + index + ')">Delete</a>';
                            return e + d;
                        }

                    }
                    }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: <%=numPerPage %>, //默认一页数据条数
                pageList:<%=SetnumPerPage() %>,
                rownumbers: true, //行号
                showFooter: true,
               
                onBeforeEdit: function (index, row) {
                    row.editing = true;
                    $('#tab_list').datagrid('refreshRow', index);
                },
                onAfterEdit: function (index, row) {
                    row.editing = false;
                    $('#tab_list').datagrid('refreshRow', index);
                },
                onCancelEdit: function (index, row) {
                    row.editing = false;
                    $('#tab_list').datagrid('refreshRow', index);
                },
                onDblClickCell: function (rowIndex, field, value) {
                    $(this).datagrid('beginEdit', rowIndex);
                    var ed = $(this).datagrid('getEditor', { index: rowIndex, field: field });
                    $(ed.target).focus();

                }

            });

        }
        //打开添加窗口
        function OpenWin() {
            $("#edit").dialog("open");
            $("#edit-buttons a:first").attr("onclick", "Add(0); return false;")
        }
        //添加或修改按钮事件
        function Add(uid) {
            if (!$("#form_edit").form("validate")) {
                return;
            }
            var json = GetInputData('edit', 'add');
            json.id = uid;
            $.post(location.href, json, function (data) {
                $.messager.alert('提示', data, 'info', function () {
                    if (data.indexOf("功") > 0) {
                       // console.info(data);
                        $("#tab_list").datagrid("load");
                        $("#edit").dialog("close");
                    }
                });
            });
        }
        //获取提交到服务器端的数据，[]
        //id为数据所在DIV或其它容器HTML　ID
        //cmd 为后台处理方法 以action= 为格式
        function GetInputData(id, cmd) {
            var postdata = "{ \"action\":\"" + cmd + "\",";
            $("#" + id + " input[type!='checkbox']").each(function () {
                postdata += "\"" + $(this).attr("name") + "\":\"" + $(this).val() + "\",";
            });
            $("#" + id + " input[type='checkbox']").each(function () {
                postdata += "\"" + $(this).attr("name") + "\":\"" + this.checked + "\",";
            });
            postdata = postdata.substr(0, postdata.length - 1);
            postdata += "}";
            return eval("(" + postdata + ")");
        }

        function EditData(obja,id) {
            var $this = $(obja);
            var title = $this.attr("title") || $this.text();
            var tabid = $this.attr("rel") || "_blank";
            var fresh = eval($this.attr("fresh") || "true");
            var external = eval($this.attr("external") || "false");


            //解决中文问题
            //var url = unescape($this.attr("href")).replaceTmById($(event.target).parents(".unitBox:first"));
            var url = $this.attr("href")

            top.navTab.openTab(tabid, url, { title: title, fresh: fresh, external: external });
        }
        //修改，通过工具栏
        function EditSingData(obja) {
            var selected = "";
            $($('#tab_list').datagrid('getSelections')).each(function () {
                selected += this.FnncLsId + ",";
            });
            selected = selected.substr(0, selected.length - 1);
            var $this = $(obja);
            var title = $this.attr("title") || $this.text();
            var tabid = $this.attr("rel") || "_blank";
            var fresh = eval($this.attr("fresh") || "true");
            var external = eval($this.attr("external") || "false");
            var url = "FXModel/FXFinanceLeaseUpdate.aspx?FnncLsId=" + selected

            top.navTab.openTab(tabid, url, { title: title, fresh: fresh, external: external });

        }
        //删除
        function DelData(obja) {
            $.messager.confirm('提示', '确认删除？', function (r) {
                if (r) {
                    var selected = "";
                    
                    $($('#tab_list').datagrid('getSelections')).each(function () {
                        selected += this.FnncLsId + ",";
                    });
                    selected = selected.substr(0, selected.length - 1);
                    if (selected == "") {
                        $.messager.alert('提示', '请选择要删除的数据！', 'info');
                        return;
                    }
                    
                    $.post(location.href, { "action": "delrow", "FnncLsId": selected }, function (data) {
                        $.messager.alert('提示', data, 'info', function () { $("#tab_list").datagrid("load"); });
                    });

                }
            });
        }


        //初始化搜索框
        function InitSearch(obj) {
            var query={action:'query',ContractNum:$("#tab_list_ContractNum").val()};
            $('#tab_list').datagrid("options").queryParams=query;
            $('#tab_list').datagrid('reload');
        }

        //打开高级查找窗口
        function AdjSearch() {
            $("#tab_search").dialog("open");
            $("#search-buttons").find("#btn_search").click(function () {
                var query = GetInputData("tab_search", "query");
                $('#tab_list').datagrid("options").queryParams = query;
                $('#tab_list').datagrid('reload');
                $("#tab_search").dialog("close");
                return false;
            });
        }

        /*行内编辑*/
       

        function editrow(index){
            $('#tab_list').datagrid('beginEdit', index);
        }
        function deleterow(index){   
            $.messager.confirm('Confirm','Are you sure?',function(r){
                if (r) {
                    //服务端处理代码

                    //
                    $('#tab_list').datagrid('deleteRow', index);   
                }   
            });   
        }
        function saverow(index) {
            //服务端处理代码
            var row = $("#tab_list").datagrid("getRows")[index];
            //alert(row);
            //alert(row.GPSStatus);
            row.action = "editrow";
            //
            $.post(location.href, row, function (data) {
                $.messager.alert('提示', data, 'info', function () { });
            });
            //
            $('#tab_list').datagrid('endEdit', index);   
        }   
        function cancelrow(index){
            $('#tab_list').datagrid('cancelEdit', index);
        }



        //日期扩展
        $.extend($.fn.datagrid.defaults.editors, {
            datebox2: {
                init: function (container, options) {
                    var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);
                    return input;
                },
                getValue: function (target) {
                    return $(target).val();
                },
                setValue: function (target, value) {
                    $(target).val(value);
                },
                resize: function (target, width) {
                    var input = $(target);
                    if ($.boxModel == true) {
                        input.width(width - (input.outerWidth() - input.width()));
                    } else {
                        input.width(width);
                    }
                }
            }
        });  
    </script>
    <script>
        //easyui　formatter　相关
        //json日期格式转换成yyyy-MM-dd
        function formatterdate(val, row) {
            if (val == null || val == undefined) {
                return "";
            }
            var match;
            if (!(match = val.match(/\d+/))) {
                return false;
            }
            var dt = new Date();
            dt.setTime(match[0] - 0);
            var str = "";
            if (dt.getFullYear) {
                var y, m, d;
                y = dt.getFullYear();
                m = dt.getMonth() + 1; //1-12
                m = "" + m;
                d = "" + dt.getDate();
                if (m.length != 2) {
                    m = "0" + m;
                }
                if (d.length != 2) {
                    d = "0" + d;
                }
                str = "" + y + "-" + m + "-" + d;
            }
            return str;
        }
        //金额转换成用有千位符
        function milliformatter(val) {//添加千位符
            var separator = ",";
            var re = /(\d{3})\B/g;
            val = val.toString();
            return val.replace(re, "$1" + separator);


        }
    </script>
</body>
</html>
